package com.neusoft.neuiotms.dcam.fixed.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.fixed.dto.StockWarningDTO;
import com.neusoft.neuiotms.dcam.fixed.service.StockWarningService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "消耗品库存预警设置")
@RestController
@RequestMapping(value = "/api/w/stockwarning")
public class StockWarningController {

    @Autowired
    private StockWarningService stockWarningService;

    @ApiOperation("查询所有")
    @GetMapping
    public ResultListDTO<StockWarningDTO> index() {
        final List<StockWarningDTO> DTOs = this.stockWarningService.findAll();
        final ResultListDTO<StockWarningDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询")
    @GetMapping("/p")
    public PageResultDTO<StockWarningDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.stockWarningService.search(pageable, searchable));
    }

    @ApiOperation("创建")
    @PostMapping
    public ResultDTO<StockWarningDTO> create(@RequestBody final StockWarningDTO dto) {
        final StockWarningDTO result = this.stockWarningService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/{id}")
    public ResultDTO<StockWarningDTO> update(@PathVariable final Long id,
            @RequestBody final StockWarningDTO dto) {
        final StockWarningDTO result = this.stockWarningService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public ResultDTO<StockWarningDTO> details(@PathVariable final Long id) {
        final StockWarningDTO dto = this.stockWarningService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除库存预警设置")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.stockWarningService.delete(id);
        return ResultDTO.success();
    }

}
